﻿CREATE procedure Sync.SP_BeginSyncSession
	@PeerId UNIQUEIDENTIFIER,
	@CommitteeName NVARCHAR(50),
	@CenterID UNIQUEIDENTIFIER,
	@IsMainCommittee bit
AS
Begin

	IF @IsMainCommittee = 1 AND NOT EXISTS 
	(
		SELECT 1 
		FROM dbo.Committees
		WHERE CommitteeID = @PeerId
	)
	BEGIN
		INSERT INTO Sync.Peers(CommitteId,LastSyncVersion,LastSyncDateTime)
		values(@PeerId,NULL,NULL)
	END 
	
	select LastSyncVersion 
	from sync.Peers 
	where CommitteId =  @PeerId AND LastSyncDateTime IS NOT NULL 
	
end


